package main

import (
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"time"
)

func getMess(want string)string{
	var getstr string
	switch want {
	case "key":
		fmt.Printf("Input your search kind(like:uname): ")
	case "value":
		fmt.Printf("Input your kind value(like:'1863351068'): ")
	case "ans":
		fmt.Printf("Input your search answer(like:version): ")
	}
	fmt.Scan(&getstr)
	return getstr
}

func inStr(str string,list []string)bool{
	for _,v := range list{
		if v == str{
			return true
		}
	}
	return false
}

func main() {
	var ans       string
	//var ret       string
	var date      string
	var key,value string


	keyStr := []string{"uid","phone","uname","account_id"}


	for {
		key = getMess("key")
		if inStr(key,keyStr) != true {
			fmt.Printf("Your search kind must be uid,phone,uname,account_id\n")
			continue
		} else {
			//todo: process key code
			fmt.Println(key)
			continue
		}
	}



	value = getMess("value")
	ans   = getMess("ans")
	date = time.Now().Format("2006") + "_" + time.Now().Format("01")

	fmt.Println(key)
	fmt.Println(value)
	fmt.Println(ans)
	fmt.Println(date)

	//db, err := sql.Open("mysql", "db_read:Yixuedb@2018@tcp(rm-uf660f9n1q498q195.mysql.rds.aliyuncs.com)/stat-offline")
	//if err != nil {
	//	fmt.Printf("err:%v", err)
	//}
	//mSql := "SELECT "+ ans + " FROM stat_sum_login_detail_"+ date + " WHERE "+ key + "=" + value + " GROUP BY " + ans
	//rows, err := db.Query(mSql)
	//if err != nil {
	//	fmt.Printf("err:%v", err)
	//	return
	//}
	//for rows.Next(){
	//	err := rows.Scan(&ret)
	//	if err != nil{
	//		fmt.Printf("err")
	//	}
	//	fmt.Printf("Your input is:\n%v,%v,your want is %v, answer is: \n%v",key,value,ans,ret)
	//}
	//defer rows.Close()
}